<!DOCTYPE HTML>
<html lang="en" >
    
    <head>
        
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <title>Redis | 课程简介</title>
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <meta name="description" content="">
        <meta name="generator" content="GitBook 2.6.7">
        
        
        <meta name="HandheldFriendly" content="true"/>
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
        <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">
        
    <link rel="stylesheet" href="../gitbook/style.css">
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-highlight/website.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-search/search.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-fontsettings/website.css">
        
    
    

        
    
    
    <link rel="next" href="../C03-Gitflow/index.html" />
    
    
    <link rel="prev" href="../C02-Database/DatabaseOptimize.html" />
    

        
    </head>
    <body>
        
        
    <div class="book"
        data-level="2.8"
        data-chapter-title="Redis"
        data-filepath="C02-Database/Redis.md"
        data-basepath=".."
        data-revision="Mon May 27 2019 03:35:45 GMT+0800 (CST)"
        data-innerlanguage="">
    

<div class="book-summary">
    <nav role="navigation">
        <ul class="summary">
            
            
            
            

            

            
    
        <li class="chapter " data-level="0" data-path="index.html">
            
                
                    <a href="../index.html">
                
                        <i class="fa fa-check"></i>
                        
                        课程简介
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1" data-path="C01-Introduction/index.html">
            
                
                    <a href="../C01-Introduction/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.</b>
                        
                        项目介绍
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1" data-path="C01-Introduction/AboutToutiaoWebVM.html">
            
                
                    <a href="../C01-Introduction/AboutToutiaoWebVM.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.1.</b>
                        
                        ToutiaoWeb虚拟机使用说明
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="C01-Introduction/PycharmRemoteDevelop.html">
            
                
                    <a href="../C01-Introduction/PycharmRemoteDevelop.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.2.</b>
                        
                        Pycharm远程开发
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="C01-Introduction/AboutProject.html">
            
                
                    <a href="../C01-Introduction/AboutProject.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.3.</b>
                        
                        产品与开发
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2" data-path="C02-Database/index.html">
            
                
                    <a href="../C02-Database/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.</b>
                        
                        数据库
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.1" data-path="C02-Database/DatabaseDesign.html">
            
                
                    <a href="../C02-Database/DatabaseDesign.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.1.</b>
                        
                        数据库设计
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="C02-Database/ORM.html">
            
                
                    <a href="../C02-Database/ORM.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.2.</b>
                        
                        理解ORM
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.3" data-path="C02-Database/SQLAlchemyMapping.html">
            
                
                    <a href="../C02-Database/SQLAlchemyMapping.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.3.</b>
                        
                        SQLAlchemy映射构建
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.4" data-path="C02-Database/SQLAlchemyOperations.html">
            
                
                    <a href="../C02-Database/SQLAlchemyOperations.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.4.</b>
                        
                        SQLAlchemy操作
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.5" data-path="C02-Database/DatabaseTheory.html">
            
                
                    <a href="../C02-Database/DatabaseTheory.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.5.</b>
                        
                        数据库理论
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.6" data-path="C02-Database/DistributedID.html">
            
                
                    <a href="../C02-Database/DistributedID.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.6.</b>
                        
                        分布式ID
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.7" data-path="C02-Database/DatabaseOptimize.html">
            
                
                    <a href="../C02-Database/DatabaseOptimize.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.7.</b>
                        
                        数据库优化
                    </a>
            
            
        </li>
    
        <li class="chapter active" data-level="2.8" data-path="C02-Database/Redis.html">
            
                
                    <a href="../C02-Database/Redis.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.8.</b>
                        
                        Redis
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3" data-path="C03-Gitflow/index.html">
            
                
                    <a href="../C03-Gitflow/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.</b>
                        
                        Git工作流
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.1" data-path="C03-Gitflow/Gitflow.html">
            
                
                    <a href="../C03-Gitflow/Gitflow.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.1.</b>
                        
                        Gitflow
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.2" data-path="C03-Gitflow/AboutGit.html">
            
                
                    <a href="../C03-Gitflow/AboutGit.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.2.</b>
                        
                        Git总结
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.3" data-path="C03-Gitflow/ProjectDirectory.html">
            
                
                    <a href="../C03-Gitflow/ProjectDirectory.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.3.</b>
                        
                        工程目录
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.4" data-path="C03-Gitflow/DebugMethod.html">
            
                
                    <a href="../C03-Gitflow/DebugMethod.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.4.</b>
                        
                        调试方法
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="4" data-path="C04-JWT/index.html">
            
                
                    <a href="../C04-JWT/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.</b>
                        
                        JWT
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.1" data-path="C04-JWT/JWT.html">
            
                
                    <a href="../C04-JWT/JWT.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.1.</b>
                        
                        JWT &amp; JWS &amp; JWE
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.2" data-path="C04-JWT/PythonLib.html">
            
                
                    <a href="../C04-JWT/PythonLib.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.2.</b>
                        
                        PythonLib
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.3" data-path="C04-JWT/Implement.html">
            
                
                    <a href="../C04-JWT/Implement.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.3.</b>
                        
                        实施方案
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.4" data-path="C04-JWT/Forbbiden.html">
            
                
                    <a href="../C04-JWT/Forbbiden.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.4.</b>
                        
                        禁用问题
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="5" data-path="C05-OSS/index.html">
            
                
                    <a href="../C05-OSS/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.</b>
                        
                        对象存储
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="5.1" data-path="C05-OSS/Qiniu.html">
            
                
                    <a href="../C05-OSS/Qiniu.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.1.</b>
                        
                        七牛云存储
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.2" data-path="C05-OSS/CDN.html">
            
                
                    <a href="../C05-OSS/CDN.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.2.</b>
                        
                        CDN
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="6" data-path="C06-Cache/index.html">
            
                
                    <a href="../C06-Cache/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.</b>
                        
                        缓存
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="6.1" data-path="C06-Cache/CacheArchitecture.html">
            
                
                    <a href="../C06-Cache/CacheArchitecture.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.1.</b>
                        
                        缓存的架构
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.2" data-path="C06-Cache/CacheData.html">
            
                
                    <a href="../C06-Cache/CacheData.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.2.</b>
                        
                        缓存的数据
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.3" data-path="C06-Cache/CacheTTLAndEviction.html">
            
                
                    <a href="../C06-Cache/CacheTTLAndEviction.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.3.</b>
                        
                        缓存的有效期与淘汰策略
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.4" data-path="C06-Cache/CachePatterns.html">
            
                
                    <a href="../C06-Cache/CachePatterns.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.4.</b>
                        
                        缓存模式
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.5" data-path="C06-Cache/CacheProblems.html">
            
                
                    <a href="../C06-Cache/CacheProblems.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.5.</b>
                        
                        缓存问题
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.6" data-path="C06-Cache/ProjectCacheAndStorageDesign.html">
            
                
                    <a href="../C06-Cache/ProjectCacheAndStorageDesign.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.6.</b>
                        
                        项目缓存与Redis持久存储设计
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.7" data-path="C06-Cache/ProjectCacheImplement.html">
            
                
                    <a href="../C06-Cache/ProjectCacheImplement.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.7.</b>
                        
                        项目缓存实现
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.8" data-path="C06-Cache/ProjectRedisStorageImplement.html">
            
                
                    <a href="../C06-Cache/ProjectRedisStorageImplement.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.8.</b>
                        
                        项目Redis持久存储实现
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="7" data-path="C07-APScheduler/index.html">
            
                
                    <a href="../C07-APScheduler/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.</b>
                        
                        APScheduler
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="7.1" data-path="C07-APScheduler/APSchedulerTutorial.html">
            
                
                    <a href="../C07-APScheduler/APSchedulerTutorial.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.1.</b>
                        
                        APScheduler使用
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.2" data-path="C07-APScheduler/FixStatistics.html">
            
                
                    <a href="../C07-APScheduler/FixStatistics.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.2.</b>
                        
                        定时修正统计数据
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="8" data-path="C08-RPC/index.html">
            
                
                    <a href="../C08-RPC/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.</b>
                        
                        RPC
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="8.1" data-path="C08-RPC/AboutRPC.html">
            
                
                    <a href="../C08-RPC/AboutRPC.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.1.</b>
                        
                        RPC简介
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8.2" data-path="C08-RPC/gRPC.html">
            
                
                    <a href="../C08-RPC/gRPC.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.2.</b>
                        
                        gRPC
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8.3" data-path="C08-RPC/ProtocolBuffers.html">
            
                
                    <a href="../C08-RPC/ProtocolBuffers.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.3.</b>
                        
                        Protocol Buffers
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8.4" data-path="C08-RPC/RecoSysIDL.html">
            
                
                    <a href="../C08-RPC/RecoSysIDL.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.4.</b>
                        
                        推荐系统接口定义
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8.5" data-path="C08-RPC/Server.html">
            
                
                    <a href="../C08-RPC/Server.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.5.</b>
                        
                        服务端
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8.6" data-path="C08-RPC/Client.html">
            
                
                    <a href="../C08-RPC/Client.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.6.</b>
                        
                        客户端
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8.7" data-path="C08-RPC/ToutiaoAPIViewImplement.html">
            
                
                    <a href="../C08-RPC/ToutiaoAPIViewImplement.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.7.</b>
                        
                        头条首页新闻推荐接口编写
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="9" data-path="C09-IM/index.html">
            
                
                    <a href="../C09-IM/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>9.</b>
                        
                        即时通信
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="9.1" data-path="C09-IM/AboutIM.html">
            
                
                    <a href="../C09-IM/AboutIM.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>9.1.</b>
                        
                        即时通信简介
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="9.2" data-path="C09-IM/WebSocket.html">
            
                
                    <a href="../C09-IM/WebSocket.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>9.2.</b>
                        
                        WebSocket
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="9.3" data-path="C09-IM/SocketIO.html">
            
                
                    <a href="../C09-IM/SocketIO.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>9.3.</b>
                        
                        Socket.IO
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="9.4" data-path="C09-IM/Chat.html">
            
                
                    <a href="../C09-IM/Chat.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>9.4.</b>
                        
                        头条聊天服务实现
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="9.5" data-path="C09-IM/MessagePush.html">
            
                
                    <a href="../C09-IM/MessagePush.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>9.5.</b>
                        
                        头条在线消息推送实现
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="10" data-path="C10-Elasticsearch/index.html">
            
                
                    <a href="../C10-Elasticsearch/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>10.</b>
                        
                        Elasticsearch
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="10.1" data-path="C10-Elasticsearch/Introduction.html">
            
                
                    <a href="../C10-Elasticsearch/Introduction.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>10.1.</b>
                        
                        简介与原理
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="10.2" data-path="C10-Elasticsearch/ConceptAndCluster.html">
            
                
                    <a href="../C10-Elasticsearch/ConceptAndCluster.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>10.2.</b>
                        
                        概念与集群
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="10.3" data-path="C10-Elasticsearch/AnalysisIK.html">
            
                
                    <a href="../C10-Elasticsearch/AnalysisIK.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>10.3.</b>
                        
                        IK中文分析器
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="10.4" data-path="C10-Elasticsearch/IndexAndType.html">
            
                
                    <a href="../C10-Elasticsearch/IndexAndType.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>10.4.</b>
                        
                        索引与类型
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="10.5" data-path="C10-Elasticsearch/Document.html">
            
                
                    <a href="../C10-Elasticsearch/Document.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>10.5.</b>
                        
                        文档
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="10.6" data-path="C10-Elasticsearch/Logstash.html">
            
                
                    <a href="../C10-Elasticsearch/Logstash.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>10.6.</b>
                        
                        Logstash导入数据
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="10.7" data-path="C10-Elasticsearch/Query.html">
            
                
                    <a href="../C10-Elasticsearch/Query.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>10.7.</b>
                        
                        查询
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="10.8" data-path="C10-Elasticsearch/ToutiaoSearchImplement.html">
            
                
                    <a href="../C10-Elasticsearch/ToutiaoSearchImplement.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>10.8.</b>
                        
                        头条全文检索实现
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="10.9" data-path="C10-Elasticsearch/Suggest.html">
            
                
                    <a href="../C10-Elasticsearch/Suggest.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>10.9.</b>
                        
                        suggest查询
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="10.10" data-path="C10-Elasticsearch/ToutiaoSuggestImplement.html">
            
                
                    <a href="../C10-Elasticsearch/ToutiaoSuggestImplement.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>10.10.</b>
                        
                        头条suggest查询实现
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="11" data-path="C11-Unittest.html">
            
                
                    <a href="../C11-Unittest.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>11.</b>
                        
                        单元测试
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="12" data-path="C12-Deployment/index.html">
            
                
                    <a href="../C12-Deployment/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>12.</b>
                        
                        部署相关
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="12.1" data-path="C12-Deployment/Gunicorn.html">
            
                
                    <a href="../C12-Deployment/Gunicorn.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>12.1.</b>
                        
                        Gunicorn
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="12.2" data-path="C12-Deployment/Supervisor.html">
            
                
                    <a href="../C12-Deployment/Supervisor.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>12.2.</b>
                        
                        Supervisor
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    


            
            <li class="divider"></li>
            <li>
                <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
                    Published with GitBook
                </a>
            </li>
            
        </ul>
    </nav>
</div>

    <div class="book-body">
        <div class="body-inner">
            <div class="book-header" role="navigation">
    <!-- Actions Left -->
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../" >课程简介</a>
    </h1>
</div>

            <div class="page-wrapper" tabindex="-1" role="main">
                <div class="page-inner">
                
                
                    <section class="normal" id="section-">
                    
                        <h1 id="redis">Redis</h1>
<h2 id="1-redis&#x4E8B;&#x52A1;">1 Redis&#x4E8B;&#x52A1;</h2>
<h4 id="&#x57FA;&#x672C;&#x4E8B;&#x52A1;&#x6307;&#x4EE4;">&#x57FA;&#x672C;&#x4E8B;&#x52A1;&#x6307;&#x4EE4;</h4>
<p>Redis&#x63D0;&#x4F9B;&#x4E86;&#x4E00;&#x5B9A;&#x7684;&#x4E8B;&#x52A1;&#x652F;&#x6301;&#xFF0C;&#x53EF;&#x4EE5;&#x4FDD;&#x8BC1;&#x4E00;&#x7EC4;&#x64CD;&#x4F5C;&#x539F;&#x5B50;&#x6267;&#x884C;&#x4E0D;&#x88AB;&#x6253;&#x65AD;&#xFF0C;&#x4F46;&#x662F;&#x5982;&#x679C;&#x6267;&#x884C;&#x4E2D;&#x51FA;&#x73B0;&#x9519;&#x8BEF;&#xFF0C;&#x4E8B;&#x52A1;&#x4E0D;&#x80FD;&#x56DE;&#x6EDA;&#xFF0C;Redis&#x672A;&#x63D0;&#x4F9B;&#x56DE;&#x6EDA;&#x652F;&#x6301;&#x3002;</p>
<ul>
<li><code>multi</code> &#x5F00;&#x542F;&#x4E8B;&#x52A1;</li>
<li><code>exec</code> &#x6267;&#x884C;&#x4E8B;&#x52A1;</li>
</ul>
<pre><code>127.0.0.1:6379&gt; multi
OK
127.0.0.1:6379&gt; set a 100
QUEUED
127.0.0.1:6379&gt; set b 200
QUEUED
127.0.0.1:6379&gt; get a
QUEUED
127.0.0.1:6379&gt; get b
QUEUED
127.0.0.1:6379&gt; exec
1) OK
2) OK
3) &quot;100&quot;
4) &quot;200&quot;
</code></pre><p>&#x4F7F;&#x7528;multi&#x5F00;&#x542F;&#x4E8B;&#x52A1;&#x540E;&#xFF0C;&#x64CD;&#x4F5C;&#x7684;&#x6307;&#x4EE4;&#x5E76;&#x672A;&#x7ACB;&#x5373;&#x6267;&#x884C;&#xFF0C;&#x800C;&#x662F;&#x88AB;redis&#x8BB0;&#x5F55;&#x5728;&#x961F;&#x5217;&#x4E2D;&#xFF0C;&#x7B49;&#x5F85;&#x4E00;&#x8D77;&#x6267;&#x884C;&#x3002;&#x5F53;&#x6267;&#x884C;exec&#x547D;&#x4EE4;&#x540E;&#xFF0C;&#x5F00;&#x59CB;&#x6267;&#x884C;&#x4E8B;&#x52A1;&#x6307;&#x4EE4;&#xFF0C;&#x6700;&#x7EC8;&#x5F97;&#x5230;&#x6BCF;&#x6761;&#x6307;&#x4EE4;&#x7684;&#x7ED3;&#x679C;&#x3002;</p>
<pre><code>127.0.0.1:6379&gt; multi
OK
127.0.0.1:6379&gt; set c 300
QUEUED
127.0.0.1:6379&gt; hgetall a
QUEUED
127.0.0.1:6379&gt; set d 400
QUEUED
127.0.0.1:6379&gt; get d
QUEUED
127.0.0.1:6379&gt; exec
1) OK
2) (error) WRONGTYPE Operation against a key holding the wrong kind of value
3) OK
4) &quot;400&quot;
127.0.0.1:6379&gt;
</code></pre><p>&#x5982;&#x679C;&#x4E8B;&#x52A1;&#x4E2D;&#x51FA;&#x73B0;&#x4E86;&#x9519;&#x8BEF;&#xFF0C;&#x4E8B;&#x52A1;&#x5E76;&#x4E0D;&#x4F1A;&#x7EC8;&#x6B62;&#x6267;&#x884C;&#xFF0C;&#x800C;&#x662F;&#x53EA;&#x4F1A;&#x8BB0;&#x5F55;&#x4E0B;&#x8FD9;&#x6761;&#x9519;&#x8BEF;&#x7684;&#x4FE1;&#x606F;&#xFF0C;&#x5E76;&#x7EE7;&#x7EED;&#x6267;&#x884C;&#x540E;&#x9762;&#x7684;&#x6307;&#x4EE4;&#x3002;&#x6240;&#x4EE5;&#x4E8B;&#x52A1;&#x4E2D;&#x51FA;&#x9519;&#x4E0D;&#x4F1A;&#x5F71;&#x54CD;&#x540E;&#x7EED;&#x6307;&#x4EE4;&#x7684;&#x6267;&#x884C;&#x3002;</p>
<h4 id="python&#x5BA2;&#x6237;&#x7AEF;&#x64CD;&#x4F5C;">Python&#x5BA2;&#x6237;&#x7AEF;&#x64CD;&#x4F5C;</h4>
<p>&#x5728;Redis&#x7684;Python &#x5BA2;&#x6237;&#x7AEF;&#x5E93;redis-py&#x4E2D;&#xFF0C;&#x63D0;&#x4F9B;&#x4E86;pipeline (&#x79F0;&#x4E3A;&#x6D41;&#x6C34;&#x7EBF; &#x6216; &#x7BA1;&#x9053;)&#xFF0C;&#x8BE5;&#x5DE5;&#x5177;&#x7684;&#x4F5C;&#x7528;&#x662F;&#xFF1A;</p>
<ul>
<li>&#x5728;&#x5BA2;&#x6237;&#x7AEF;&#x7EDF;&#x4E00;&#x6536;&#x96C6;&#x64CD;&#x4F5C;&#x6307;&#x4EE4;</li>
<li>&#x8865;&#x5145;&#x4E0A;multi&#x548C;exec&#x6307;&#x4EE4;&#xFF0C;&#x5F53;&#x4F5C;&#x4E00;&#x4E2A;&#x4E8B;&#x52A1;&#x53D1;&#x9001;&#x5230;redis&#x670D;&#x52A1;&#x5668;&#x6267;&#x884C;</li>
</ul>
<pre><code class="lang-python"><span class="hljs-keyword">from</span> redis <span class="hljs-keyword">import</span> StrictRedis
r = StrictRedis.from_url(<span class="hljs-string">&apos;redis://127.0.0.1:6381/0&apos;</span>)
pl = r.pipeline()
pl.set(<span class="hljs-string">&apos;a&apos;</span>, <span class="hljs-number">100</span>)
pl.set(<span class="hljs-string">&apos;b&apos;</span>, <span class="hljs-number">200</span>)
pl.get(<span class="hljs-string">&apos;a&apos;</span>)
pl.get(<span class="hljs-string">&apos;b&apos;</span>)
ret = pl.execute()
print(ret) <span class="hljs-comment">#  [True, True, b&apos;100&apos;, b&apos;200&apos;]</span>
</code></pre>
<h4 id="watch&#x76D1;&#x89C6;">watch&#x76D1;&#x89C6;</h4>
<p>&#x82E5;&#x5728;&#x6784;&#x5EFA;&#x7684;redis&#x4E8B;&#x52A1;&#x5728;&#x6267;&#x884C;&#x65F6;&#x4F9D;&#x8D56;&#x67D0;&#x4E9B;&#x503C;&#xFF0C;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;watch&#x5BF9;&#x6570;&#x636E;&#x503C;&#x8FDB;&#x884C;&#x76D1;&#x89C6;&#x3002;</p>
<pre><code>127.0.0.1:6379&gt; set stock 100
OK
127.0.0.1:6379&gt; watch stock
OK
127.0.0.1:6379&gt; multi
OK
127.0.0.1:6379&gt; incrby stock -1
QUEUED
127.0.0.1:6379&gt; incr sales
QUEUED
127.0.0.1:6379&gt; exec
1) (integer) 99
2) (integer) 1
</code></pre><p>&#x4E8B;&#x52A1;exec&#x6267;&#x884C;&#x524D;&#x88AB;&#x76D1;&#x89C6;&#x7684;stock&#x503C;&#x672A;&#x53D8;&#x5316;&#xFF0C;&#x4E8B;&#x52A1;&#x6B63;&#x786E;&#x6267;&#x884C;&#x3002;</p>
<pre><code>127.0.0.1:6379&gt; set stock 100
OK
127.0.0.1:6379&gt; watch stock
OK
127.0.0.1:6379&gt; multi
OK
127.0.0.1:6379&gt; incrby stock -1
QUEUED
127.0.0.1:6379&gt; incr sales
QUEUED
</code></pre><p>&#x6B64;&#x65F6;&#x5728;&#x53E6;&#x4E00;&#x4E2A;&#x5BA2;&#x6237;&#x7AEF;&#x4FEE;&#x6539;stock&#x7684;&#x503C;&#xFF0C;&#x6267;&#x884C;</p>
<pre><code>127.0.0.1:6379&gt; incrby stock -2
(integer) 98
</code></pre><p>&#x5F53;&#x7B2C;&#x4E00;&#x4E2A;&#x5BA2;&#x6237;&#x7AEF;&#x518D;&#x6267;&#x884C;exec&#x65F6;</p>
<pre><code>127.0.0.1:6379&gt; exec
(nil)
</code></pre><p>&#x8868;&#x660E;&#x4E8B;&#x52A1;&#x9700;&#x8981;&#x76D1;&#x89C6;&#x7684;stock&#x503C;&#x53D1;&#x751F;&#x4E86;&#x53D8;&#x5316;&#xFF0C;&#x4E8B;&#x52A1;&#x4E0D;&#x80FD;&#x6267;&#x884C;&#x4E86;&#x3002;</p>
<p><strong>&#x6CE8;&#x610F;&#xFF1A;Redis Cluster &#x96C6;&#x7FA4;&#x4E0D;&#x652F;&#x6301;&#x4E8B;&#x52A1;</strong></p>
<h2 id="2-redis&#x6301;&#x4E45;&#x5316;">2 Redis&#x6301;&#x4E45;&#x5316;</h2>
<p>redis&#x53EF;&#x4EE5;&#x5C06;&#x6570;&#x636E;&#x5199;&#x5165;&#x5230;&#x78C1;&#x76D8;&#x4E2D;&#xFF0C;&#x5728;&#x505C;&#x673A;&#x6216;&#x5B95;&#x673A;&#x540E;&#xFF0C;&#x518D;&#x6B21;&#x542F;&#x52A8;redis&#x65F6;&#xFF0C;&#x5C06;&#x78C1;&#x76D8;&#x4E2D;&#x7684;&#x5907;&#x4EFD;&#x6570;&#x636E;&#x52A0;&#x8F7D;&#x5230;&#x5185;&#x5B58;&#x4E2D;&#x6062;&#x590D;&#x4F7F;&#x7528;&#x3002;&#x8FD9;&#x662F;redis&#x7684;&#x6301;&#x4E45;&#x5316;&#x3002;&#x6301;&#x4E45;&#x5316;&#x6709;&#x5982;&#x4E0B;&#x4E24;&#x79CD;&#x673A;&#x5236;&#x3002;</p>
<h4 id="rdb-&#x5FEB;&#x7167;&#x6301;&#x4E45;&#x5316;">RDB &#x5FEB;&#x7167;&#x6301;&#x4E45;&#x5316;</h4>
<p>redis&#x53EF;&#x4EE5;&#x5C06;&#x5185;&#x5B58;&#x4E2D;&#x7684;&#x6570;&#x636E;&#x5199;&#x5165;&#x78C1;&#x76D8;&#x8FDB;&#x884C;&#x6301;&#x4E45;&#x5316;&#x3002;&#x5728;&#x8FDB;&#x884C;&#x6301;&#x4E45;&#x5316;&#x65F6;&#xFF0C;redis&#x4F1A;&#x521B;&#x5EFA;&#x5B50;&#x8FDB;&#x7A0B;&#x6765;&#x6267;&#x884C;&#x3002;</p>
<p><strong>redis&#x9ED8;&#x8BA4;&#x5F00;&#x542F;&#x4E86;&#x5FEB;&#x7167;&#x6301;&#x4E45;&#x5316;&#x673A;&#x5236;&#x3002;</strong></p>
<p>&#x8FDB;&#x884C;&#x5FEB;&#x7167;&#x6301;&#x4E45;&#x5316;&#x7684;&#x65F6;&#x673A;&#x5982;&#x4E0B;</p>
<ul>
<li><p>&#x5B9A;&#x671F;&#x89E6;&#x53D1;</p>
<p>  redis&#x7684;&#x914D;&#x7F6E;&#x6587;&#x4EF6;</p>
<pre><code class="lang-shell">  #   save <seconds> <changes>
  #
  #   Will save the DB if both the given number of seconds and the given
  #   number of write operations against the DB occurred.
  #
  #   In the example below the behaviour will be to save:
  #   after 900 sec (15 min) if at least 1 key changed
  #   after 300 sec (5 min) if at least 10 keys changed
  #   after 60 sec if at least 10000 keys changed
  #
  #   Note: you can disable saving completely by commenting out all &quot;save&quot; lines.
  #
  #   It is also possible to remove all the previously configured save
  #   points by adding a save directive with a single empty string argument
  #   like in the following example:
  #
  #   save &quot;&quot;

  save 900 1
  save 300 10
  save 60 10000
</changes></seconds></code></pre>
</li>
<li><p>BGSAVE </p>
<p>  &#x6267;&#x884C;<code>BGSAVE</code>&#x547D;&#x4EE4;&#xFF0C;&#x624B;&#x52A8;&#x89E6;&#x53D1;RDB&#x6301;&#x4E45;&#x5316;</p>
</li>
<li><p>SHUTDOWN</p>
<p>  &#x5173;&#x95ED;redis&#x65F6;&#x89E6;&#x53D1;</p>
</li>
</ul>
<h4 id="aof-&#x8FFD;&#x52A0;&#x6587;&#x4EF6;&#x6301;&#x4E45;&#x5316;">AOF &#x8FFD;&#x52A0;&#x6587;&#x4EF6;&#x6301;&#x4E45;&#x5316;</h4>
<p>redis&#x53EF;&#x4EE5;&#x5C06;&#x6267;&#x884C;&#x7684;&#x6240;&#x6709;&#x6307;&#x4EE4;&#x8FFD;&#x52A0;&#x8BB0;&#x5F55;&#x5230;&#x6587;&#x4EF6;&#x4E2D;&#x6301;&#x4E45;&#x5316;&#x5B58;&#x50A8;&#xFF0C;&#x8FD9;&#x662F;redis&#x7684;&#x53E6;&#x4E00;&#x79CD;&#x6301;&#x4E45;&#x5316;&#x673A;&#x5236;&#x3002;</p>
<p><strong>redis&#x9ED8;&#x8BA4;&#x672A;&#x5F00;&#x542F;AOF&#x673A;&#x5236;&#x3002;</strong></p>
<p>redis&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x914D;&#x7F6E;&#x5982;&#x4E0B;&#x9879;&#x5F00;&#x542F;AOF&#x673A;&#x5236;</p>
<pre><code class="lang-shell">appendonly yes  # &#x662F;&#x5426;&#x5F00;&#x542F;AOF
appendfilename &quot;appendonly.aof&quot;  # AOF&#x6587;&#x4EF6;
</code></pre>
<p>AOF&#x673A;&#x5236;&#x8BB0;&#x5F55;&#x64CD;&#x4F5C;&#x7684;&#x65F6;&#x673A;</p>
<pre><code class="lang-shell"># appendfsync always  # &#x6BCF;&#x4E2A;&#x64CD;&#x4F5C;&#x90FD;&#x5199;&#x5230;&#x78C1;&#x76D8;&#x4E2D;
appendfsync everysec  # &#x6BCF;&#x79D2;&#x5199;&#x4E00;&#x6B21;&#x78C1;&#x76D8;&#xFF0C;&#x9ED8;&#x8BA4;
# appendfsync no  # &#x7531;&#x64CD;&#x4F5C;&#x7CFB;&#x7EDF;&#x51B3;&#x5B9A;&#x5199;&#x5165;&#x78C1;&#x76D8;&#x7684;&#x65F6;&#x673A;
</code></pre>
<p>&#x4F7F;&#x7528;AOF&#x673A;&#x5236;&#x7684;&#x7F3A;&#x70B9;&#x662F;&#x968F;&#x7740;&#x65F6;&#x95F4;&#x7684;&#x6D41;&#x901D;&#xFF0C;AOF&#x6587;&#x4EF6;&#x4F1A;&#x53D8;&#x5F97;&#x5F88;&#x5927;&#x3002;&#x4F46;redis&#x53EF;&#x4EE5;&#x538B;&#x7F29;AOF&#x6587;&#x4EF6;&#x3002;</p>
<h4 id="&#x7ED3;&#x5408;&#x4F7F;&#x7528;">&#x7ED3;&#x5408;&#x4F7F;&#x7528;</h4>
<p>redis&#x5141;&#x8BB8;&#x6211;&#x4EEC;&#x540C;&#x65F6;&#x4F7F;&#x7528;&#x4E24;&#x79CD;&#x673A;&#x5236;&#xFF0C;&#x901A;&#x5E38;&#x60C5;&#x51B5;&#x4E0B;&#x6211;&#x4EEC;&#x4F1A;&#x8BBE;&#x7F6E;AOF&#x673A;&#x5236;&#x4E3A;everysec &#x6BCF;&#x79D2;&#x5199;&#x5165;&#xFF0C;&#x5219;&#x6700;&#x574F;&#x4EC5;&#x4F1A;&#x4E22;&#x5931;&#x4E00;&#x79D2;&#x5185;&#x7684;&#x6570;&#x636E;&#x3002;</p>
<h2 id="3-redis&#x9AD8;&#x53EF;&#x7528;">3 Redis&#x9AD8;&#x53EF;&#x7528;</h2>
<p>&#x4E3A;&#x4E86;&#x4FDD;&#x8BC1;redis&#x6700;&#x5927;&#x7A0B;&#x5EA6;&#x4E0A;&#x80FD;&#x591F;&#x4F7F;&#x7528;&#xFF0C;redis&#x63D0;&#x4F9B;&#x4E86;&#x4E3B;&#x4ECE;&#x540C;&#x6B65;+Sentinel&#x54E8;&#x5175;&#x673A;&#x5236;&#x3002;</p>
<h4 id="sentinel-&#x54E8;&#x5175;">Sentinel &#x54E8;&#x5175;</h4>
<p><a href="https://redis.io/topics/sentinel" target="_blank">https://redis.io/topics/sentinel</a></p>
<p>redis&#x63D0;&#x4F9B;&#x7684;&#x54E8;&#x5175;&#x662F;&#x7528;&#x6765;&#x770B;&#x62A4;redis&#x5B9E;&#x4F8B;&#x8FDB;&#x7A0B;&#x7684;&#xFF0C;&#x53EF;&#x4EE5;&#x81EA;&#x52A8;&#x8FDB;&#x884C;&#x6545;&#x969C;&#x8F6C;&#x79FB;&#xFF0C;&#x5176;&#x529F;&#x80FD;&#x5982;&#x4E0B;&#xFF1A;</p>
<ul>
<li><strong>Monitoring</strong>. Sentinel constantly checks if your master and slave instances are working as expected.</li>
<li><strong>Notification</strong>. Sentinel can notify the system administrator, another computer programs, via an API, that something is wrong with one of the monitored Redis instances.</li>
<li><strong>Automatic failover</strong>. If a master is not working as expected, Sentinel can start a failover process where a slave is promoted to master, the other additional slaves are reconfigured to use the new master, and the applications using the Redis server informed about the new address to use when connecting.</li>
<li><strong>Configuration provider</strong>. Sentinel acts as a source of authority for clients service discovery: clients connect to Sentinels in order to ask for the address of the current Redis master responsible for a given service. If a failover occurs, Sentinels will report the new address</li>
</ul>
<p>&#x5728;redis&#x5B89;&#x88C5;&#x540E;&#xFF0C;&#x4F1A;&#x81EA;&#x5E26;sentinel&#x54E8;&#x5175;&#x7A0B;&#x5E8F;&#xFF0C;&#x4FEE;&#x6539;sentinel.conf&#x914D;&#x7F6E;&#x6587;&#x4EF6;</p>
<pre><code class="lang-shell">bind 127.0.0.1
port 26380
daemonize yes
logfile /var/log/redis-sentinel.log
sentinel monitor mymaster 127.0.0.1 6380 2
sentinel down-after-milliseconds mymaster 30000
sentinel parallel-syncs mymaster 1
sentinel failover-timeout mymaster 180000
</code></pre>
<ul>
<li>sentinel monitor mymaster 127.0.0.1 6380 2 &#x8BF4;&#x660E;<ul>
<li>mymaster &#x4E3A;sentinel&#x76D1;&#x62A4;&#x7684;redis&#x4E3B;&#x4ECE;&#x96C6;&#x7FA4;&#x8D77;&#x540D;</li>
<li>127.0.0.1 6300 &#x4E3A;&#x4E3B;&#x4ECE;&#x4E2D;&#x4EFB;&#x4E00;&#x53F0;&#x673A;&#x5668;&#x5730;&#x5740;</li>
<li>2 &#x8868;&#x793A;&#x6709;&#x4E24;&#x53F0;&#x4EE5;&#x7684;sentinel&#x8BA4;&#x4E3A;&#x67D0;&#x4E00;&#x53F0;redis&#x5B95;&#x673A;&#x540E;&#xFF0C;&#x624D;&#x4F1A;&#x8FDB;&#x884C;&#x81EA;&#x52A8;&#x6545;&#x969C;&#x8F6C;&#x79FB;&#x3002;</li>
</ul>
</li>
</ul>
<p>&#x542F;&#x52A8;&#x65B9;&#x5F0F;&#xFF1A;</p>
<pre><code class="lang-shell">redis-sentinel sentinel.conf
</code></pre>
<h4 id="&#x9AD8;&#x53EF;&#x7528;&#x65B9;&#x6848;&#x6CE8;&#x610F;&#x4E8B;&#x9879;">&#x9AD8;&#x53EF;&#x7528;&#x65B9;&#x6848;&#x6CE8;&#x610F;&#x4E8B;&#x9879;</h4>
<ul>
<li>&#x81F3;&#x5C11;&#x4E09;&#x4E2A;sentinel&#x4EE5;&#x4E0A; </li>
<li>sentinel&#x8981;&#x5206;&#x6563;&#x8FD0;&#x884C;&#x5728;&#x4E0D;&#x540C;&#x7684;&#x673A;&#x5668;&#x4E0A;</li>
</ul>
<h4 id="python&#x5BA2;&#x6237;&#x7AEF;&#x4F7F;&#x7528;">Python&#x5BA2;&#x6237;&#x7AEF;&#x4F7F;&#x7528;</h4>
<pre><code class="lang-python"><span class="hljs-comment"># redis &#x54E8;&#x5175;</span>
REDIS_SENTINELS = [
    (<span class="hljs-string">&apos;127.0.0.1&apos;</span>, <span class="hljs-string">&apos;26380&apos;</span>),
    (<span class="hljs-string">&apos;127.0.0.1&apos;</span>, <span class="hljs-string">&apos;26381&apos;</span>),
    (<span class="hljs-string">&apos;127.0.0.1&apos;</span>, <span class="hljs-string">&apos;26382&apos;</span>),
]
REDIS_SENTINEL_SERVICE_NAME = <span class="hljs-string">&apos;mymaster&apos;</span>

<span class="hljs-keyword">from</span> redis.sentinel <span class="hljs-keyword">import</span> Sentinel
_sentinel = Sentinel(REDIS_SENTINELS)
redis_master = _sentinel.master_for(REDIS_SENTINEL_SERVICE_NAME)
redis_slave = _sentinel.slave_for(REDIS_SENTINEL_SERVICE_NAME)
</code></pre>
<p>&#x4F7F;&#x7528;&#x793A;&#x4F8B;</p>
<pre><code class="lang-python"><span class="hljs-comment"># &#x8BFB;&#x6570;&#x636E;&#xFF0C;master&#x8BFB;&#x4E0D;&#x5230;&#x53BB;slave&#x8BFB;</span>
<span class="hljs-keyword">try</span>:
    real_code = redis_master.get(key)
<span class="hljs-keyword">except</span> ConnectionError <span class="hljs-keyword">as</span> e:
    real_code = redis_slave.get(key)

<span class="hljs-comment"># &#x5199;&#x6570;&#x636E;&#xFF0C;&#x53EA;&#x80FD;&#x5728;master&#x91CC;&#x5199;</span>
<span class="hljs-keyword">try</span>:
    current_app.redis_master.delete(key)
<span class="hljs-keyword">except</span> ConnectionError <span class="hljs-keyword">as</span> e:
    logger.error(e)
</code></pre>
<h2 id="4-redis&#x96C6;&#x7FA4;">4 Redis&#x96C6;&#x7FA4;</h2>
<p><a href="https://redis.io/topics/partitioning" target="_blank">https://redis.io/topics/partitioning</a></p>
<p>Reids Cluster&#x96C6;&#x7FA4;&#x65B9;&#x6848;&#xFF0C;&#x5185;&#x90E8;&#x5DF2;&#x7ECF;&#x96C6;&#x6210;&#x4E86;sentinel&#x673A;&#x5236;&#x6765;&#x505A;&#x5230;&#x9AD8;&#x53EF;&#x7528;&#x3002;</p>
<h4 id="python&#x5BA2;&#x6237;&#x7AEF;">Python&#x5BA2;&#x6237;&#x7AEF;</h4>
<pre><code class="lang-python"><span class="hljs-comment"># redis &#x96C6;&#x7FA4;</span>
REDIS_CLUSTER = [
    {<span class="hljs-string">&apos;host&apos;</span>: <span class="hljs-string">&apos;127.0.0.1&apos;</span>, <span class="hljs-string">&apos;port&apos;</span>: <span class="hljs-string">&apos;7000&apos;</span>},
    {<span class="hljs-string">&apos;host&apos;</span>: <span class="hljs-string">&apos;127.0.0.1&apos;</span>, <span class="hljs-string">&apos;port&apos;</span>: <span class="hljs-string">&apos;7001&apos;</span>},
    {<span class="hljs-string">&apos;host&apos;</span>: <span class="hljs-string">&apos;127.0.0.1&apos;</span>, <span class="hljs-string">&apos;port&apos;</span>: <span class="hljs-string">&apos;7002&apos;</span>},
]

<span class="hljs-keyword">from</span> rediscluster <span class="hljs-keyword">import</span> StrictRedisCluster
redis_cluster = StrictRedisCluster(startup_nodes=REDIS_CLUSTER)

<span class="hljs-comment"># &#x53EF;&#x4EE5;&#x5C06;redis_cluster&#x5C31;&#x5F53;&#x4F5C;&#x666E;&#x901A;&#x7684;redis&#x5BA2;&#x6237;&#x7AEF;&#x4F7F;&#x7528;</span>
redis_master.delete(key)
</code></pre>
<h4 id="&#x6CE8;&#x610F;&#xFF1A;">&#x6CE8;&#x610F;&#xFF1A;</h4>
<ul>
<li>redis cluster &#x4E0D;&#x652F;&#x6301;&#x4E8B;&#x52A1;</li>
<li>redis cluster &#x4E0D;&#x652F;&#x6301;&#x591A;&#x952E;&#x64CD;&#x4F5C;&#xFF0C;&#x5982;mset</li>
</ul>
<h2 id="5-&#x7528;&#x9014;">5 &#x7528;&#x9014;</h2>
<ul>
<li>&#x7F13;&#x5B58;</li>
<li>&#x6301;&#x4E45;&#x5B58;&#x50A8;<ul>
<li>&#x6570;&#x636E;&#x5E93;&#x7684;&#x7EDF;&#x8BA1;&#x5197;&#x4F59;&#x5B57;&#x6BB5; &#x653E;&#x5230; redis&#x4E2D;&#x4FDD;&#x5B58;</li>
</ul>
</li>
</ul>
<h2 id="6--&#x76F8;&#x5173;&#x8865;&#x5145;&#x9605;&#x8BFB;">6  &#x76F8;&#x5173;&#x8865;&#x5145;&#x9605;&#x8BFB;</h2>
<ul>
<li><a href="https://redis.io/documentation" target="_blank">https://redis.io/documentation</a></li>
<li>&#x300A;Redis&#x5B9E;&#x8DF5;&#x300B; &#xFF08;Redis in action)</li>
</ul>

                    
                    </section>
                
                
                </div>
            </div>
        </div>

        
        <a href="../C02-Database/DatabaseOptimize.html" class="navigation navigation-prev " aria-label="Previous page: 数据库优化"><i class="fa fa-angle-left"></i></a>
        
        
        <a href="../C03-Gitflow/index.html" class="navigation navigation-next " aria-label="Next page: Git工作流"><i class="fa fa-angle-right"></i></a>
        
    </div>
</div>

        
<script src="../gitbook/app.js"></script>

    
    <script src="../gitbook/plugins/gitbook-plugin-search/lunr.min.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-search/search.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-sharing/buttons.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-fontsettings/buttons.js"></script>
    

<script>
require(["gitbook"], function(gitbook) {
    var config = {"highlight":{},"search":{"maxIndexSize":1000000},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2}};
    gitbook.start(config);
});
</script>

        
    </body>
    
</html>
